package com.yxjx.duoxue.datamodel;

import java.io.Serializable;

import com.yxjx.duoxue.datamodel.course.DMCourse;
import com.yxjx.duoxue.datamodel.school.DMSchool;
import com.yxjx.duoxue.network.NwUtils;
import com.yxjx.duoxue.network.UserLoginResponse;
import com.yxjx.duoxue.utils.Utils;

import android.content.Context;

public class DMCallRecord implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = -8973812460682614557L;
	private String sid;
	private int type;
	private long id;
	private String version;
	private String device;
	private int dbId;
	
	public String getSid() {
		return sid;
	}
	public void setSid(String sid) {
		this.sid = sid;
	}
	public int getType() {
		return type;
	}
	public void setType(int type) {
		this.type = type;
	}
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}
	public String getVersion() {
		return version;
	}
	public void setVersion(String version) {
		this.version = version;
	}
	public String getDevice() {
		return device;
	}
	public void setDevice(String device) {
		this.device = device;
	}
	
	// 将课程／学校／活动记录构成一条电话记录。
	public static DMCallRecord from(Object item, Context context) {
		if (item == null) {
			return null;
		}
		DMCallRecord record = new DMCallRecord();
		record.setDevice(Utils.getFullDeviceId(context));
		record.setVersion(Utils.getAllVersionInfo(context));
		UserLoginResponse ulRsp = UserLoginResponse.getInstance(context);
		if (ulRsp != null) {
			record.setSid(ulRsp.getSid());
		}
		if (item instanceof DMActivity) {
			record.setType(NwUtils.RECORD_TYPE_ACTIVITY);
			record.setId(((DMActivity) item).getActivityId());
		} else if (item instanceof DMCourse) {
			record.setType(NwUtils.RECORD_TYPE_COURSE);
			record.setId(((DMCourse) item).getCourseId());
		} else if (item instanceof DMSchool) {
			record.setType(NwUtils.RECORD_TYPE_SCHOOL);
			record.setId(((DMSchool) item).getId());
		}
		return record;
	}
	public int getDbId() {
		return dbId;
	}
	public void setDbId(int dbId) {
		this.dbId = dbId;
	}
	
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("\ndbId:" + getDbId());
		sb.append("\nid:" + getId());
		sb.append("\nsid:" + getSid());
		sb.append("\ntype:" + getType());
		sb.append("\nversion:" + getVersion());
		sb.append("\ndevice:" + getDevice());
		return sb.toString();
	}

}
